package com.lujianfei.compose

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.graphics.toArgb
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewmodel.compose.viewModel
import com.lujianfei.compose.ui.public.FunctionList
import com.lujianfei.compose.ui.public.Page
import com.lujianfei.compose.ui.theme.CustomThemeManager
import com.lujianfei.compose.ui.theme.ThemeType

val titleLiveData = MutableLiveData<String>()

class MainActivity : ComponentActivity() {

    @ExperimentalFoundationApi
    @ExperimentalMaterialApi
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            val rememberTitle: String by titleLiveData.observeAsState("Compose Demo")
            val themType = ThemeType.Default
            val wrappedColor = CustomThemeManager.getWrappedColor(themType)
            window.statusBarColor = wrappedColor.lightColors.primary.toArgb()
            Page(title = rememberTitle, themType = themType, isDarkTheme = false) {
                Content()
            }
        }
    }
}

@ExperimentalFoundationApi
@ExperimentalMaterialApi
@Composable
fun Content() {
    Main()
}

@ExperimentalMaterialApi
@ExperimentalFoundationApi
@Composable
fun Main() {
    titleLiveData.value = "Compose Demo shit"
    val viewModel: MainViewModel = viewModel()
    FunctionList(functions = viewModel.functions)
}